package com.nulldev.util.concurrency.threadIt.v4.emapi.testing;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.concurrency.threadIt.v4.asyncTasks.AsyncTaskCallback;
import com.nulldev.util.concurrency.threadIt.v4.emapi.ft.FutureTask;
import com.nulldev.util.concurrency.threadIt.v4.emapi.uft.Executable;

public class TaskRejectionTest {

	public static void main(String[] args) {
		final Executable<Object> o = new FutureTask<Object>() {

			@Override
			public Object execute() {
				/* NO-OP */
				return 3;
			}
		};
		/* Don't actually call this. */
		o.rejectSubmission();
		JVM.println("Attempting waitTillCompletion()...");
		try {
			JVM.println("waitTillCompletion: " + o.waitTillCompletion());
		} catch (Exception ex) {
			JVM.errorln(ex);
		}
		JVM.println("Attempting addCallbackTask()...");
		o.addCallbackTask(new AsyncTaskCallback<Object>() {

			@Override
			public void onCompletion(Object result) {
				JVM.println("addCallbackTask: onCompletion()");
			}

			@Override
			public void onError(Throwable e) {
				JVM.println("addCallbackTask: onError()");
			}

			@Override
			public void onSubmissionRejection() {
				JVM.println("addCallbackTask: onSubmissionRejection()");
			}
		});
	}

}
